package com.situ.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.situ.bean.Dept;
import com.situ.mapper.DeptMapper;
import com.situ.service.DeptService;

@Service
public class DeptServiceImpl implements DeptService {

	@Autowired
	private DeptMapper deptMapper;

	@Override
	public Dept add(Dept dept) {
		// 先插入数据
		deptMapper.insert(dept);
		// 再根据ID查询数据返回
		return deptMapper.selectByPrimaryKey(dept.getId());
	}

	@Override
	public Dept remove(Integer id) {
		// 先查出记录
		Dept dept = deptMapper.selectByPrimaryKey(id);
		// 再删除
		deptMapper.deleteByPrimaryKey(id);
		return dept;
	}

	@Override
	public Dept edit(Dept dept) {
		// 先修改完成
		deptMapper.updateByPrimaryKey(dept);
		// 再根据ＩＤ查询记录 返回
		return deptMapper.selectByPrimaryKey(dept.getId());
	}

	@Override
	public Dept getById(Integer id) {
		return deptMapper.selectByPrimaryKey(id);
	}

	@Override
	public List getAll() {
		return deptMapper.selectAll();
	}

}
